/*
 * Copyright (C) 2011-2016 Markus Junginger, greenrobot (http://greenrobot.org)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.greenrobot.greendao.internal;

import java.util.List;

import ohos.data.rdb.DataObserver;
import ohos.data.resultset.ResultSet;
import ohos.data.resultset.SharedBlock;
import ohos.utils.PacMap;
import ohos.utils.net.Uri;

/** Internal class used by greenDAO. */
public final class FastCursor implements ResultSet {
    private final SharedBlock window;
    private int position;
    private final int count;

    /**
     * Constrctor for FastCursor
     * @param window ResultSet window
     */
    public FastCursor(SharedBlock window) {
        this.window = window;
        count = window.getRowCount();
    }

    @Override
    public int getRowCount() {
        return window.getRowCount();
    }

    @Override
    public int getRowIndex() {
        return position;
    }

    @Override
    public boolean goTo(int offset) {
        return goToRow(position + offset);
    }

    @Override
    public boolean goToRow(int position) {
        if (position >= 0 && position < count) {
            this.position = position;
            return true;
        } else {
            return false;
        }
    }

    @Override
    public boolean goToFirstRow() {
        position = 0;
        return count > 0;
    }

    @Override
    public boolean goToLastRow() {
        if (count > 0) {
            position = count - 1;
            return true;
        } else {
            return false;
        }
    }

    @Override
    public boolean goToNextRow() {
        if (position < count - 1) {
            position++;
            return true;
        } else {
            return false;
        }
    }

    @Override
    public boolean goToPreviousRow() {
        if (position > 0) {
            position--;
            return true;
        } else {
            return false;
        }
    }

    @Override
    public boolean isAtFirstRow() {
        return position == 0;
    }

    @Override
    public boolean isAtLastRow() {
        return position == count - 1;
    }

    @Override
    public boolean isStarted() {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean isEnded() {
        throw new UnsupportedOperationException();
    }

    @Override
    public int getColumnIndexForName(String columnName) {
        throw new UnsupportedOperationException();
    }

    @Override
    public String getColumnNameForIndex(int columnIndex) {
        throw new UnsupportedOperationException();
    }

    @Override
    public String[] getAllColumnNames() {
        throw new UnsupportedOperationException();
    }

    @Override
    public int getColumnCount() {
        throw new UnsupportedOperationException();
    }

    @Override
    public byte[] getBlob(int columnIndex) {
        return window.getBlob(position, columnIndex);
    }

    @Override
    public String getString(int columnIndex) {
        return window.getString(position, columnIndex);
    }

    @Override
    public short getShort(int columnIndex) {
        return window.getShort(position, columnIndex);
    }

    @Override
    public int getInt(int columnIndex) {
        return window.getInt(position, columnIndex);
    }

    @Override
    public long getLong(int columnIndex) {
        return window.getLong(position, columnIndex);
    }

    @Override
    public float getFloat(int columnIndex) {
        return window.getFloat(position, columnIndex);
    }

    @Override
    public double getDouble(int columnIndex) {
        return window.getDouble(position, columnIndex);
    }

    @SuppressWarnings("deprecation")
    @Override
    public boolean isColumnNull(int columnIndex) {
        return (window.getType(position, columnIndex) == ResultSet.ColumnType.TYPE_NULL);
    }

    @Override
    public void close() {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean isClosed() {
        throw new UnsupportedOperationException();
    }

    @Override
    public void registerObserver(DataObserver observer) {
        throw new UnsupportedOperationException();
    }

    @Override
    public void unregisterObserver(DataObserver observer) {
        throw new UnsupportedOperationException();
    }

    /**
     * Not to allow to set the extension
     * @param extensions extensions to set
     */
    public void setExtensions(PacMap extensions) {
        throw new UnsupportedOperationException();
    }

    @Override
    public PacMap getExtensions() {
        throw new UnsupportedOperationException();
    }

    @Override
    public void setAffectedByUris(Object o, List<Uri> list) {
        throw new UnsupportedOperationException();
    }

    @Override
    public List<Uri> getAffectedByUris() {
        throw new UnsupportedOperationException();
    }

    /**
     * gets the type
     * @param columnIndex columnIndex
     * @return type
     */
    public int getType(int columnIndex) {
        throw new UnsupportedOperationException();
    }

    @Override
    public ColumnType getColumnTypeForIndex(int columnIndex) {
        throw new UnsupportedOperationException();
    }

    /**
     * gets the notification Uri
     * @return Uri
     */
    public Uri getNotificationUri() {
        return null;
    }

}
